Skip to content

[fix][client] Fix OpenTelemetryProducerInterceptor not executing due to eligible check#25585

Merged
congbobo184 merged 6 commits into
apache:masterfrom
hrzzzz:fix-otel-not-work
May 11, 2026
Merged

[fix][client] Fix OpenTelemetryProducerInterceptor not executing due to eligible check#25585
congbobo184 merged 6 commits into
apache:masterfrom
hrzzzz:fix-otel-not-work

Conversation

@hrzzzz
Copy link
Copy Markdown
Contributor

@hrzzzz hrzzzz commented Apr 27, 2026

Fixes #25584

Motivation

OpenTelemetryProducerInterceptor had a deadlock:

  1. eligible() returns tracer != null && propagator != null — both null after construction.
  2. ProducerInterceptors.beforeSend() checks eligible() first, and skips the interceptor entirely if it returns false.
  3. Tracer and propagator are initialized in beforeSend() via initializeIfNeeded(producer), which is never reached.

The interceptor was effectively a no-op — it never created any spans.

Modifications

Remove the lazy-initialization pattern and inject InstrumentProvider at construction time instead. The InstrumentProvider is already available in both ProducerBuilderImpl and ConsumerBuilderImpl where the interceptors are created:

  • OpenTelemetryProducerInterceptor — accepts InstrumentProvider in constructor, initializes tracer and propagator eagerly. Removes initializeIfNeeded() and the initialized flag.
  • OpenTelemetryConsumerInterceptor — same treatment for consistency.
  • ProducerBuilderImpl / ConsumerBuilderImpl — pass client.instrumentProvider() to the constructor.

Verifying this change

  • Make sure that the change passes the CI checks.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

@hrzzzz
Copy link
Copy Markdown
Contributor Author

hrzzzz commented Apr 29, 2026

@Technoboy- @lhotari @codelipenghui @poorbarcode Could you please review this PR? Thanks

ruihongzhou added 2 commits May 7, 2026 17:46
@congbobo184 congbobo184 requested a review from Technoboy- May 9, 2026 06:03
ruihongzhou added 2 commits May 11, 2026 11:27
Copy link
Copy Markdown
Contributor

@congbobo184 congbobo184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@congbobo184 congbobo184 merged commit 8ffedda into apache:master May 11, 2026
43 checks passed
@congbobo184 congbobo184 added the type/bug The PR fixed a bug or issue reported a bug label May 11, 2026
@congbobo184 congbobo184 added this to the 5.0.0-M1 milestone May 11, 2026
@hrzzzz hrzzzz deleted the fix-otel-not-work branch May 11, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OpenTelemetryProducerInterceptor not executing due to eligible check

3 participants